<template>
  <div id="bckColor">

    <div id="topCardBkb">

      <div class="textStyle1">退款渠道选择</div>
      <span class="textStyle111">审核期间可先授权退资渠道，审核完成后可快速退款</span>
      <!--    列表start-->
      <div v-for="(item,position) in refundChannelList"
           :key="position"
           @click="clickTable(position)">
        <!--    支付宝-->
        <div class="balanceListLayout" v-show="item.retFlag == '2'">

          <div class="balanceListItem1">
            <div class="imgChannel">
              <img
                class="itemImg"
                src="../../assets/img/icon_alipay.png"
                alt/>
              <div class="textStyle2">支付宝 {{ retAccount2 }}</div>
            </div>

            <div class="imgChannel" v-if="!item.refundAccId">
              <div class="textStyle3" @click="gotoAuthorization">去授权</div>
              <img
                class="itemImg1"
                src="../../assets/img/icon_right_gray_arrow.png"
                alt/>
            </div>

            <div v-else>

              <div class="imgChannel" v-if="selectindex != position">
                <img
                  class="itemImg2"
                  src="../../assets/img/icon_item_unselect.png"
                  alt/>
              </div>

              <div class="imgChannel" v-if="selectindex == position">
                <img
                  class="itemImg2"
                  src="../../assets/img/icon_item_select.png"
                  alt/>
              </div>

            </div>


          </div>
          <div class="balanceListItemLayout" v-show="item.refundAccId">

            <div class="line1"/>
            <div class="balanceListItem2">
              <div class="textStyle4" @click="replaseUserId">更换支付宝账号</div>
              <div class="textStyle4" @click="unBindUserId">解绑支付宝</div>
            </div>

          </div>

        </div>

        <!--    微信-->
        <div class="balanceListLayout" v-show="item.retFlag == '3'">

          <div class="balanceListItem1">
            <div class="imgChannel">
              <img
                class="itemImg"
                src="../../assets/img/icon_wechat.png"
                alt/>
              <div class="textStyle2">微信 {{ retAccount3 }}</div>
            </div>

            <div class="imgChannel" v-if="!item.refundAccId">
              <div class="textStyle3" @click="gotoAuthorization">去授权</div>
              <img
                class="itemImg1"
                src="../../assets/img/icon_right_gray_arrow.png"
                alt/>
            </div>

            <div v-else>

              <div class="imgChannel" v-if="selectindex != position">
                <img
                  class="itemImg2"
                  src="../../assets/img/icon_item_unselect.png"
                  alt/>
              </div>

              <div class="imgChannel" v-if="selectindex == position">
                <img
                  class="itemImg2"
                  src="../../assets/img/icon_item_select.png"
                  alt/>
              </div>

            </div>

          </div>
          <div class="balanceListItemLayout" v-show="item.refundAccId">

            <div class="line1"/>
            <div class="balanceListItem2">
              <div class="textStyle4" @click="replaseUserId">更换微信账号</div>
              <div class="textStyle4" @click="unBindUserId">解绑微信</div>
            </div>

          </div>

        </div>


      </div>
      <!--    列表end-->


    </div>

    <!--    <span class="textStyle1111">备注：60个自然日内的贷记卡充值金额将原路返回。</span>-->

    <button class="disabled1" v-on:click="nextClickChannel">
      <div style="font-size: 14px">下一步</div>
    </button>

    <loading :loadingShow="loadingShow"></loading>
  </div>
</template>

<script>
import loading from "./loading/loading";

import {
  queryRefundChannel,
  authorizeRemove,
  alipayAuorizeInit,
  alipayAuorize,
  queryBalanceDetails,
  weixinAuorizeInit,
  userInfoEntry
} from "../../api/index";

export default {
  data() {
    return {
      isProd: "",//1生产,0测试
      pay3BaseUrl: "",//网络平台3.1根路径
      Authorization: "",//3.1请求的头Authorization
      customerId: "",
      userMobile: "",
      userLoginId: "",
      tokenStr: "",
      showFrandAmtflag: false,
      queryFrandAmtflag: false,
      loadingShow: false, //loading show
      htFlag: true,
      cardNo: "1234567890123456789",
      balance: "2000",
      htCardFlag: "1",
      refundChannelList: [],
      selectChannel: {},
      selectindex: -1,
      refundChannelType: "",
      mUserId: "",
      retAccount2: "",
      retAccount3: "",
      proof: ""
    };
  },
  created() {
    let proof = this.$route.query.proof;  //接受参数关键代码
    this.proof = proof;
    console.log("页面跳转携带过来的参数", this.proof)
  },
  mounted() {

    //隐藏返回键
    BmacJSBridge.call("showBackButton", {
      showBack: "1",
    });

    BmacJSBridge.call('hideOptionMenu');

    let timer = setTimeout(() => {

      BmacJSBridge.call('obtainClientBaseUrl', (data) => {
        console.log("obtainClientBaseUrl", data);
        this.isProd = data.isProd;
        this.pay3BaseUrl = data.pay3BaseUrl;
        this.Authorization = data.Authorization;




      });

      this.getuserToken();
      this.getBasicInfo();
      clearTimeout(timer);
      timer = null;
    }, 200);

  },
  filters: {
    formatCardNum(testNum) {
      return testNum.replace(/(\d{4})/g, '$1 ').replace(/\s*$/, '');

    },
    balanceFilter(balance) {
      if (!isNaN(Number(balance))) {
        return (Number(balance) / 100).toFixed(2);
      } else {
        return "0.00";
      }
    },
    cardReg(cardNo) {
      if (cardNo) {
        var str = cardNo.substr(0, 1);
        if (str == "0") {
          var carNoStr = cardNo.substr(1);
          return carNoStr.replace(/(\d{4})(\d+)(\d{4})$/, "$1 **** $3");
        } else {
          return cardNo.replace(/(\d{4})(\d+)(\d{4})$/, "$1 **** $3");
        }
      }
    },
    selectCardNo(cardNo) {
      if (cardNo) {
        let str = cardNo.substr(0, 1);
        if (str == "0") {
          cardNo = cardNo.substr(1);
        } else {
          cardNo = cardNo;
        }
        let cardlength = cardNo.length / 4;
        let cardStr = "";
        let dataArr = [];
        for (let index = 0; index < cardlength; index++) {
          dataArr.push(cardNo.substr(index * 4, 4));
        }
        for (let index = 0; index < dataArr.length; index++) {
          cardStr += dataArr[index] + " ";
        }
        return cardStr;
      }
    },
  },
  methods: {
    nextClickChannel() {
      // this.$router.push({path: '/resultPage', query: {data: ""}})
      // console.log("点了下一步",this.selectChannel);
      if (this.selectChannel.userId) {
        var txnType = "";
        if (this.selectChannel.retFlag == '2') {
          txnType = "19";
        } else if (this.selectChannel.retFlag == '3') {
          txnType = "09";
        }
        this.userInfoEntryRequest(this.selectChannel.userId, txnType, this.selectChannel.userName, this.selectChannel.retAccount);
      } else {
        this.$toast("请选择退资渠道");
      }

    },
    replaseUserId() {
      let embedding = {
        eventID: "replaseUserId", //商品ID
        extra: {
          name: "更换微信号",
        },
      };
      BmacJSBridge.call("AddEventburyPoints", embedding, (data) => {});
      //更换
      setTimeout(() => {

        if (this.selectChannel.retFlag == '2') {
          this.alipayAuthorization();
        } else if (this.selectChannel.retFlag == '3') {
          this.weixinAuthorization();
        }

      }, 200);

    },
    unBindUserId() {
      let embedding = {
        eventID: "unBindUserId", //商品ID
        extra: {
          name: "解绑微信号",
        },
      };
      BmacJSBridge.call("AddEventburyPoints", embedding, (data) => {});
      //解绑
      setTimeout(() => {
        // if (this.selectChannel.retFlag == '2') {
        //   this.$toast("点击了解绑支付宝账号");
        // } else if (this.selectChannel.retFlag == '3') {
        //   this.$toast("点击了解绑微信账号");
        // }
        this.unBuildRefundChannel();
      }, 200);

    },
    gotoAuthorization() {
      let embedding = {
        eventID: "gotoAuthorization", //商品ID
        extra: {
          name: "去授权",
        },
      };
      BmacJSBridge.call("AddEventburyPoints", embedding, (data) => {});
      //去授权
      setTimeout(() => {
        if (this.selectChannel.retFlag == '2') {//支付宝
          this.alipayAuthorization();
        } else if (this.selectChannel.retFlag == '3') {//微信
          this.weixinAuthorization();
        }

      }, 200);
    },
    clickTable(position) {
      this.selectindex = position;
      this.selectChannel = this.refundChannelList[position];

      if (this.selectChannel.retFlag == '2') {
        //支付宝
        this.refundChannelType = "19";
        this.mUserId = this.selectChannel.userId;
      } else if (this.selectChannel.retFlag == '3') {
        //微信
        this.refundChannelType = "09";
        this.mUserId = this.selectChannel.userId;
      }

    },
    /**
     * 解绑退资渠道
     * */
    unBuildRefundChannel() {
      this.loadingShow = true;
      var request = {
        channelId: "75111023",
        clientType: "Android",
        channelType: "MOB",
        channelCode: "3103",
        merId: "003070000001",
        customerId: this.customerId,
        mobileNo: this.userMobile,
        logonId: this.userLoginId,
        refundChannelId: this.selectChannel.retFlag
      }
      console.log("解绑请求", request);

      BmacJSBridge.call("encryptDataWithRSA3", request, (encryData) => {
        this.$ajax({
          method: "post",
          url: this.pay3BaseUrl + `${authorizeRemove}`,
          headers: {
            "Content-Type": "application/json",
            Authorization: this.Authorization,
            "wolf-auth": this.tokenStr,
          },
          data: encryData.encryptedData,
        }).then(
          (responseData) => {
            this.loadingShow = false;
            BmacJSBridge.call(
              "decryptDataWithRSA3", {decryptParam: responseData.data}, (decryData) => {
                let res = decryData.encryptedData;
                let dataDic = res.data;
                console.log("解绑响应", dataDic);

                if (dataDic.retCode == "0000") {
                  this.$toast("解除绑定成功");
                  this.getGetRefundChannelRequest();
                } else {
                  this.$toast(dataDic.retMsg);
                }
              }
            );
          }
        ).catch((error) => {
          this.loadingShow = false;
          console.log(error);
          BmacJSBridge.call(
            "decryptDataWithRSA3",
            {decryptParam: error.response.data},
            (decryData) => {
              let errorRes = decryData.encryptedData;

              if (errorRes.code == 401) {
                this.$toast(errorRes.msg);
                BmacJSBridge.call('startApp', {
                  appId: '00000060',
                  passData: {},
                  popNum: '-1',
                  type:'1',
                  closeCurrentApp: true
                }, function (result) {
                  // noop
                  BmacJSBridge.call('closePageToHome');
                });
              } else {
                this.$toast("网络开小差");
              }

            }
          );
        });


      });


    },
    /**
     * 退资渠道查询
     * */
    getGetRefundChannelRequest() {
      this.loadingShow = true;
      var request = {
        channelId: "75111023",
        clientType: "Android",
        channelType: "MOB",
        channelCode: "3103",
        merId: "003070000001",
        customerId: this.customerId,
        mobileNo: this.userMobile,
        goodsId: "TSMSK"
      };
      console.log("退资渠道查询请求", request);
      BmacJSBridge.call("encryptDataWithRSA3", request, (encryData) => {
        this.$ajax({
          method: "post",
          url: this.pay3BaseUrl + `${queryRefundChannel}`,
          headers: {
            "Content-Type": "application/json",
            Authorization: this.Authorization,
            "wolf-auth": this.tokenStr,
          },
          data: encryData.encryptedData,
        }).then(
          (responseData) => {
            this.loadingShow = false;
            BmacJSBridge.call(
              "decryptDataWithRSA3", {decryptParam: responseData.data}, (decryData) => {
                let res = decryData.encryptedData;
                let dataDic = res.data;
                console.log("退资渠道查询响应", dataDic);

                if (dataDic.retCode == "0000") {
                  let dataList = dataDic.refundChanelList;
                  this.selectChannel = {};
                  this.selectindex = -1;
                  this.refundChannelList = [];
                  this.refundChannelList.push({
                    retFlag: "2",
                    retAccount: "",
                    refundAccId: "",
                    userName: "",
                    userId: ""
                  }, {
                    retFlag: "3",
                    retAccount: "",
                    refundAccId: "",
                    userName: "",
                    userId: ""
                  });

                  dataList.forEach((item, position) => {
                    console.log("退资渠道查询响应-item:", item);
                    console.log("退资渠道查询响应-refundAccId.length:", item.refundAccId);
                    if ((item.refundAccId && item.refundAccId > 0)) {

                      for (let i = 0; i < this.refundChannelList.length; i++) {

                        if (item.retFlag == this.refundChannelList[i].retFlag) {

                          this.refundChannelList.splice(i, 1, item);

                        }

                      }

                    }

                  });
                  console.log("退资渠道查询响应-refundChannelList---2:", this.refundChannelList);
                  // this.selectChannel = this.refundChannelList[0];
                  this.showItemUserName(this.refundChannelList);
                } else {
                  this.$toast(dataDic.retMsg);
                }
              }
            );
          }
        ).catch((error) => {
          this.loadingShow = false;
          console.log(error);
          BmacJSBridge.call(
            "decryptDataWithRSA3",
            {decryptParam: error.response.data},
            (decryData) => {
              let errorRes = decryData.encryptedData;

              if (errorRes.code == 401) {
                this.$toast(errorRes.msg);
                BmacJSBridge.call('startApp', {
                  appId: '00000060',
                  passData: {},
                  popNum: '-1',
                  type:'1',
                  closeCurrentApp: true
                }, function (result) {
                  // noop
                  BmacJSBridge.call('closePageToHome');
                });
              } else {
                this.$toast("网络开小差");
              }

            }
          );
        });


      });


    },
    showItemUserName(mList) {
      for (let i = 0; i < mList.length; i++) {
        let element = mList[i];
        let userName = element.userName;
        let retAccount = element.retAccount;
        let userId = element.userId;
        if (element.retFlag == "2") {
          if (element.refundAccId) {
            this.retAccount2 = this.checkItemUserName(userName, retAccount, userId);
          } else {
            this.retAccount2 = "";
          }
        } else if (element.retFlag == "3") {
          if (element.refundAccId) {
            this.retAccount3 = this.checkItemUserName(userName, retAccount, userId);
          } else {
            this.retAccount3 = "";
          }

        }

      }

    },
    checkItemUserName(userName, retAccount, userId) {
      if (userName) {
        if (userName.length < 2) {
          return userName;
        } else {
          let e = userName.substr(1, userName.length);
          return "*" + e;

        }

      } else if (userId) {
        if (userId.length > 12) {
          let replace = userId.replace(/(\S{4})(\S+)(\S{4})$/, "$1 **** $3");
          console.log("userId.length", replace)
          return replace;
        } else {
          return userId;
        }

      } else if (retAccount) {

        return "(" + retAccount + ")"
      } else {
        return "(- -)";

      }

    },
    /**
     * 微信授权
     * */
    weixinAuthorization() {
      BmacJSBridge.call("WeiXinRefundAmtAuthorization", (data) => {
        if (data.error) {
          this.$toast(data.error);

        } else {

          this.loadingShow = true;
          let request = {
            channelId: "75111023",
            clientType: "Android",
            channelType: "MOB",
            channelCode: "3103",
            merId: "003070000001",
            customerId: this.customerId,
            mobileNo: this.userMobile,
            code: data.result
          }
          console.log("微信授权请求", request);

          BmacJSBridge.call("encryptDataWithRSA3", request, (encryData) => {
            this.$ajax({
              method: "post",
              url: this.pay3BaseUrl + `${weixinAuorizeInit}`,
              headers: {
                "Content-Type": "application/json",
                Authorization: this.Authorization,
                "wolf-auth": this.tokenStr,
              },
              data: encryData.encryptedData,
            }).then(
              (responseData) => {
                this.loadingShow = false;
                BmacJSBridge.call(
                  "decryptDataWithRSA3", {decryptParam: responseData.data}, (decryData) => {
                    let res = decryData.encryptedData;
                    let dataDic = res.data;
                    console.log("微信授权响应", dataDic);

                    if (dataDic.retCode == "0000") {
                      this.$toast("绑定成功");
                      this.getGetRefundChannelRequest();

                    } else {
                      this.$toast(dataDic.retMsg + "-授权异常-U");
                    }
                  }
                );
              }
            ).catch((error) => {
              this.loadingShow = false;
              console.log("微信授权响应 catch:", error);
              BmacJSBridge.call(
                "decryptDataWithRSA3",
                {decryptParam: error.response.data},
                (decryData) => {
                  let errorRes = decryData.encryptedData;

                  if (errorRes.code == 401) {
                    this.$toast(errorRes.msg);
                    BmacJSBridge.call('startApp', {
                      appId: '00000060',
                      passData: {},
                      popNum: '-1',
                      type:'1',
                      closeCurrentApp: true
                    }, function (result) {
                      // noop
                      BmacJSBridge.call('closePageToHome');
                    });
                  } else {
                    this.$toast("网络开小差");
                  }

                }
              );
            });

          });


        }

      });
    },
    /**
     *
     * 支付宝授权
     * */
    alipayAuthorization() {

      this.loadingShow = true;
      var request = {
        channelId: "75111023",
        clientType: "Android",
        channelType: "MOB",
        channelCode: "3103",
        merId: "003070000001",
        customerId: this.customerId,
        mobileNo: this.userMobile,
        logonId: this.userLoginId
      }
      console.log("支付宝授权请求", request);

      BmacJSBridge.call("encryptDataWithRSA3", request, (encryData) => {
        this.$ajax({
          method: "post",
          url: this.pay3BaseUrl + `${alipayAuorizeInit}`,
          headers: {
            "Content-Type": "application/json",
            Authorization: this.Authorization,
            "wolf-auth": this.tokenStr,
          },
          data: encryData.encryptedData,
        }).then(
          (responseData) => {
            this.loadingShow = false;
            BmacJSBridge.call(
              "decryptDataWithRSA3", {decryptParam: responseData.data}, (decryData) => {
                let res = decryData.encryptedData;
                let dataDic = res.data;
                console.log("支付宝授权响应", dataDic);

                if (dataDic.retCode == "0000") {
                  BmacJSBridge.call("skipAlipayAuthorization", {accredit_url: dataDic.accredit_url}, (url) => {
                    console.log("支付宝授权结果", url.responJson);
                    let data = JSON.parse(url.responJson);
                    if (data.result == 1) {
                      console.log("支付宝授权结果-authCode", data.authCode);
                      //支付宝的授权确认
                      this.alipayAuorizeEnter(data.authCode);
                    } else {
                      this.$toast(data.message);
                    }

                  });

                } else {
                  this.$toast(dataDic.retMsg + "-授权异常-U");
                }
              }
            );
          }
        ).catch((error) => {
          this.loadingShow = false;
          console.log(error);
          BmacJSBridge.call(
            "decryptDataWithRSA3",
            {decryptParam: error.response.data},
            (decryData) => {
              let errorRes = decryData.encryptedData;

              if (errorRes.code == 401) {
                this.$toast(errorRes.msg);
                BmacJSBridge.call('startApp', {
                  appId: '00000060',
                  passData: {},
                  popNum: '-1',
                  type:'1',
                  closeCurrentApp: true
                }, function (result) {
                  // noop
                  BmacJSBridge.call('closePageToHome');
                });
              } else {
                this.$toast("网络开小差");
              }

            }
          );
        });

      });


    },
    /**
     * 支付宝的授权确认
     * */
    alipayAuorizeEnter(authCode) {

      this.loadingShow = true;
      var request = {
        channelId: "75111023",
        clientType: "Android",
        channelType: "MOB",
        channelCode: "3103",
        merId: "003070000001",
        customerId: this.customerId,
        mobileNo: this.userMobile,
        logonId: this.userLoginId,
        authCode: authCode
      }
      console.log("支付宝授权-确认请求", request);

      BmacJSBridge.call("encryptDataWithRSA3", request, (encryData) => {
        this.$ajax({
          method: "post",
          url: this.pay3BaseUrl + `${alipayAuorize}`,
          headers: {
            "Content-Type": "application/json",
            Authorization: this.Authorization,
            "wolf-auth": this.tokenStr,
          },
          data: encryData.encryptedData,
        }).then(
          (responseData) => {
            this.loadingShow = false;
            BmacJSBridge.call(
              "decryptDataWithRSA3", {decryptParam: responseData.data}, (decryData) => {
                let res = decryData.encryptedData;
                let dataDic = res.data;
                console.log("支付宝授权-确认响应", dataDic);

                if (dataDic.retCode == "0000") {

                  this.$toast("绑定成功");
                  this.getGetRefundChannelRequest();
                } else {
                  this.$toast(dataDic.retMsg + "-授权异常-U");
                }
              }
            );
          }
        ).catch((error) => {
          this.loadingShow = false;
          console.log(error);
          BmacJSBridge.call(
            "decryptDataWithRSA3",
            {decryptParam: error.response.data},
            (decryData) => {
              let errorRes = decryData.encryptedData;

              if (errorRes.code == 401) {
                this.$toast(errorRes.msg);
                BmacJSBridge.call('startApp', {
                  appId: '00000060',
                  passData: {},
                  popNum: '-1',
                  type:'1',
                  closeCurrentApp: true
                }, function (result) {
                  // noop
                  BmacJSBridge.call('closePageToHome');
                });
              } else {
                this.$toast("网络开小差");
              }

            }
          );
        });

      });


    },
    showFrandAmtDetail() {
      this.showFrandAmtflag = !this.showFrandAmtflag;
    },
    queryFrandAmtDetail() {
      // this.queryFrandAmtflag = !this.queryFrandAmtflag;

      BmacJSBridge.call("initWalletInstance", (data) => {
        console.log("初始化钱包实例对象", data);

        if (data.result) {

          BmacJSBridge.call("queryCplcWallet", (data) => {
            console.log("获取CPLC", data);
            if (data.error) {
              this.$toast(data.error);

            } else {
              console.log("获取seid", data.result.data.seid);
              this.queryBalanceDetailsMethod(data.result.data.seid);

            }

            BmacJSBridge.call("destroyWalletInstance", (data) => {
              console.log("销毁钱包对象", data);
            });

          });

        } else {
          BmacJSBridge.call("destroyWalletInstance", (data) => {
            console.log("销毁钱包对象", data);
          });
        }


      });

    },
    /**
     * 坏卡用户信息录入
     * */
    userInfoEntryRequest(mAccountNo, mTxnType, userName, retAccount) {
      this.loadingShow = true;
      var request = {};
      if (userName) {
        request = {
          channelId: "75111023",
          clientType: "Android",
          channelType: "MOB",
          channelCode: "3103",
          merId: "003070000001",
          proof: this.proof,
          txnType: mTxnType,
          accountNo: mAccountNo,
          userName: userName,
          customerId: this.customerId,//客户号
          mobileNo: this.userMobile
        };
      } else {
        request = {
          channelId: "75111023",
          clientType: "Android",
          channelType: "MOB",
          channelCode: "3103",
          merId: "003070000001",
          proof: this.proof,
          txnType: mTxnType,
          accountNo: mAccountNo,
          customerId: this.customerId,//客户号
          mobileNo: this.userMobile
        };
      }


      console.log("坏卡用户信息录入-请求:", request);

      //调用原生加密数据方法
      BmacJSBridge.call("encryptDataWithRSA3", request, (encryData) => {
        this.$ajax({
          method: "post",
          url: this.pay3BaseUrl + `${userInfoEntry}`,
          headers: {
            "Content-Type": "application/json",
            Authorization: this.Authorization,
            "wolf-auth": this.tokenStr,
          },
          data: encryData.encryptedData,
        }).then((responseData) => {
          this.loadingShow = false;
          //请求成功  调用原生解密数据方法
          BmacJSBridge.call(
            "decryptDataWithRSA3",
            {decryptParam: responseData.data},
            (decryData) => {
              let res = decryData.encryptedData;
              let dataDic = res.data;

              console.log("坏卡用户信息录入-响应:", dataDic);

              if (dataDic.retCode == "0000") {
                // dataDic["userName"] = userName;
                // dataDic["userId"] = mAccountNo;
                // dataDic["retAccount"] = retAccount;
                /**
                 * 跳转结果页
                 */
                this.$router.push({path: '/resultPage', query: {data: dataDic}})

              } else {
                this.$toast(dataDic.retMsg);
                this.loadingShow = false;
              }
            }
          );
        })
          .catch((error) => {
            this.loadingShow = false;
            console.log(error);
            BmacJSBridge.call(
              "decryptDataWithRSA3",
              {decryptParam: error.response.data},
              (decryData) => {
                let errorRes = decryData.encryptedData;

                if (errorRes.code == 401) {
                  this.$toast(errorRes.msg);
                  BmacJSBridge.call('startApp', {
                    appId: '00000060',
                    passData: {},
                    popNum: '-1',
                    type:'1',
                    closeCurrentApp: true
                  }, function (result) {
                    // noop
                   BmacJSBridge.call('closePageToHome');
                  });
                } else {
                  this.$toast("网络开小差");
                }

              }
            );
          });
      });

    },
    /**
     * 查询可退金额
     * */
    queryBalanceDetailsMethod(seid) {

      this.loadingShow = true;
      var request = {
        channelId: "75111023",
        clientType: "Android",
        channelType: "MOB",
        channelCode: "3103",
        merId: "003070000001",
        seid: seid,
        cardNo: this.cardNo,
        balance: this.balance,
        htCardFlag: this.htCardFlag
      }
      console.log("查询可退金额请求", request);

      BmacJSBridge.call("encryptDataWithRSA3", request, (encryData) => {
        this.$ajax({
          method: "post",
          url: this.pay3BaseUrl + `${queryBalanceDetails}`,
          headers: {
            "Content-Type": "application/json",
            Authorization: this.Authorization,
            "wolf-auth": this.tokenStr,
          },
          data: encryData.encryptedData,
        }).then(
          (responseData) => {
            this.loadingShow = false;
            BmacJSBridge.call(
              "decryptDataWithRSA3", {decryptParam: responseData.data}, (decryData) => {
                let res = decryData.encryptedData;
                let dataDic = res.data;
                console.log("查询可退金额响应", dataDic);

                if (dataDic.retCode == "0000") {
                  let refundBalanceList = dataDic.list;
                  console.log("查询可退金额列表", refundBalanceList);

                } else {
                  this.$toast(dataDic.retMsg);
                }
              }
            );
          }
        ).catch((error) => {
          this.loadingShow = false;
          console.log(error);
          BmacJSBridge.call(
            "decryptDataWithRSA3",
            {decryptParam: error.response.data},
            (decryData) => {
              let errorRes = decryData.encryptedData;

              if (errorRes.code == 401) {
                this.$toast(errorRes.msg);
                BmacJSBridge.call('startApp', {
                  appId: '00000060',
                  passData: {},
                  popNum: '-1',
                  type:'1',
                  closeCurrentApp: true
                }, function (result) {
                  // noop
                  BmacJSBridge.call('closePageToHome');
                });
              } else {
                this.$toast("网络开小差");
              }

            }
          );
        });

      });

    },
    getBasicInfo() {
      BmacJSBridge.call("getBasicInfo", {}, (data) => {
        let phoneData = data.deviceData;
        this.clientIp = phoneData.clientIp;
        this.terminalIp = phoneData.terminalIp;
        this.terminalMac = phoneData.terminalMac;
        this.imei = phoneData.imei;
        this.appVersion = phoneData.version;
        this.mobileType = phoneData.mobileType;
      });
    },
    /**
     * 检查是否登录
     */
    getuserToken() {

      BmacJSBridge.call(
        "getAPDataStorage",
        {
          //获取登录信息
          type: "common",
          business: "userInfoGrid",
          key: "userInfo",
        },
        (result) => {
          if (result.error == "11" && result.errorMessage == "未找到该数据") {
            //未登录跳转登录
            console.log("退出登录");
            this.jumpToLogin();
          } else {
            // console.log("87777", JSON.parse(result.data).data);
            let userInfo = JSON.parse(result.data).data;
            this.userInfo = userInfo;
            this.customerId = userInfo.customerId;
            this.userLoginId = userInfo.logonIds;
            this.userMobile = userInfo.mobileNo;
            this.tokenStr = userInfo.token_type + " " + userInfo.access_token;
            console.log("检查登录", userInfo);

            setTimeout(() => {
              this.getGetRefundChannelRequest();

            }, 200);

          }
        }
      );
    },
    jumpToLogin() {
      BmacJSBridge.call(
        "startApp",
        {
          appId: "00000060",
          type:'1',
          closeCurrentApp: true,
        },
        (result) => {
          // noop
        }
      );
    },
    isEmpty(obj) {
      if (typeof obj == "undefined" || obj == null || obj == "") {
        return true;
      } else {
        return false;
      }
    }

  },
  components: {
    loading,
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
* {
  box-sizing: border-box;
}

#bckColor {
  background: #F5F5F5;
  width: 100%;
  height: 100%;
  display: -webkit-flex;
  display: flex;
  flex-direction: column;
  padding: 16px 16px 16px 14px;
}

#topCardBkb {
  background: white;
  width: 100%;
  height: auto;
  border-radius: 10px;

}

.line1 {
  width: 100%;
  height: 1px;
  background: #cccccc;
}

.textStyle1 {
  width: 310px;
  height: 20px;
  margin-left: 16px;
  margin-top: 20px;
  font-size: 17px;
  line-height: 20px;
  display: flex;
  align-items: center;
  color: #333333;
}

.textStyle111 {
  width: 311px;
  height: 12px;
  margin-left: 16px;
  margin-top: 8px;
  /* Regular/Font Size - 12 */

  font-size: 12px;
  line-height: 12px;
  /* identical to box height, or 100% */

  display: flex;
  align-items: center;

  /* 999999 */

  color: #999999;
}

.textStyle1111 {
  width: 311px;
  height: 12px;
  margin-top: 8px;
  /* Regular/Font Size - 12 */

  font-size: 12px;
  line-height: 12px;
  /* identical to box height, or 100% */

  display: flex;
  align-items: center;

  /* 999999 */

  color: #999999;
}

.balanceListLayout {
  background: white;
  width: 100%;
  height: auto;
  border-radius: 10px;
  padding-left: 16px;
  padding-right: 16px;
  margin-top: 14px;
  flex-direction: column;
  display: flex;
  display: -webkit-flex;
  align-items: center;
  justify-content: space-between;
}

.balanceListItemLayout {
  background: white;
  width: 100%;
  height: auto;
  border-radius: 10px;
  flex-direction: column;
  display: flex;
  display: -webkit-flex;
  align-items: center;
  justify-content: space-between;
}

.itemImg {
  width: 20px;
  height: 20px;

}

.textStyle2 {
  font-size: 14px;
  color: #333333;
  line-height: 16px;
  display: flex;
  display: -webkit-flex;
  margin-left: 16px;
  flex-direction: row;
}

.imgChannel {
  width: auto;
  height: 52px;
  display: flex;
  display: -webkit-flex;
  flex-direction: row;
  align-items: center;
}

.textStyle3 {
  font-size: 14px;
  color: #999999;
  line-height: 16px;
  display: flex;
  display: -webkit-flex;
  flex-direction: row;
  align-items: baseline;
}

.itemImg1 {
  width: 6px;
  height: 12px;
  margin-left: 16px;

}

.itemImg2 {
  width: 24px;
  height: 24px;

}

.balanceListItem1 {
  width: 100%;
  height: 52px;
  flex-direction: row;
  display: flex;
  display: -webkit-flex;
  align-items: center;
  justify-content: space-between;
}

.balanceListItem2 {
  width: 100%;
  height: 40px;
  flex-direction: row;
  display: flex;
  display: -webkit-flex;
  align-items: center;
  justify-content: space-between;
}

.textStyle4 {
  font-size: 12px;
  color: #008DEE;
  line-height: 12px;
  display: flex;
  display: -webkit-flex;
  flex-direction: row;
  align-items: baseline;
}


.disabled1 {
  border: 4px solid #cccccc;
  background: #008DEE;
  color: white;
  border-radius: 4px;
  width: 100%;
  height: 44px;
  padding: 0px 16px;
  margin-top: 16px;
  font-size: 14px;
  line-height: 44px;
  border-radius: 4px;
  border: none;
}

</style>


